﻿

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 边沿算子
    /// </summary>
    [Filter("边缘检测", FilterType.Algorithm)]
    public class AlgorithmCanny : FilterBase
    {
        private Mat edges = new Mat();

       /// <summary>
        /// 阈值1
        /// </summary>
        [InputParameter("阈值1")]
        public double Threshold1 { get; set; }
        /// <summary>
        /// 阈值2
        /// </summary>
        [InputParameter("阈值2")]
        public double Threshold2 { get; set; }
        /// <summary>
        /// 查找到校
        /// </summary>
        [InputParameter("大小")]
        public ApertureSize ApertureSize { get; set; } = ApertureSize.Size5;
        /// <summary>
        /// L2梯度
        /// </summary>
        [InputParameter("L2梯度")]
        public bool L2gradient { get; set; }
        private  Mat Edges = new Mat();
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
            try
            {
              
                Cv2.Canny(mat, Edges, Threshold1, Threshold2, (int)ApertureSize, L2gradient);
                return ResultData<Mat>.Accept(TextResource.find_complete, Edges);
            }
            catch (System.Exception err)
            {
                return ResultData<Mat>.Reject(err.Message, null);
            }

        }
    }
}
